#include "StdAfx.h"
#include "CircuitGraph.h"


CCircuitGraph::CCircuitGraph(void)
{
	m_dblStartPosX = 0.0;
	m_dblStartPosY = 0.0;
	m_dblEndPosX = 0.0;
	m_dblEndPosY = 0.0;
	m_dblWidth = 0.0;
	m_dblBorderColor[0] = 0.0;
	m_dblBorderColor[1] = 0.0;
	m_dblBorderColor[2] = 0.0;
	m_bSelected = false;
	m_bBorderOn = false;
	m_bXYRatio = false;
	m_szFileName = _T("");
}

CCircuitGraph::CCircuitGraph(const CCircuitGraph *pEntityObj)
	: CCircuitUnit(pEntityObj)
{
	m_dblStartPosX = pEntityObj->GetStartPosX();
	m_dblStartPosY = pEntityObj->GetStartPosY();
	m_dblEndPosX = pEntityObj->GetEndPosX();
	m_dblEndPosY = pEntityObj->GetEndPosY();
	m_dblWidth = pEntityObj->GetBoderWidth();
	m_dblBorderColor[0] = pEntityObj->GetColorR();
	m_dblBorderColor[1] = pEntityObj->GetColorG();
	m_dblBorderColor[2] = pEntityObj->GetColorB();
	m_bSelected = pEntityObj->IsSelect();
	m_bBorderOn = pEntityObj->IsBorderOn();
	m_bXYRatio = pEntityObj->IsXYRatio();
}

CCircuitGraph::CCircuitGraph(CICircuit *pParentEnt)
	: CCircuitUnit(pParentEnt)
{
	m_dblStartPosX = 0.0;
	m_dblStartPosY = 0.0;
	m_dblEndPosX = 0.0;
	m_dblEndPosY = 0.0;
	m_dblWidth = 0.0;
	m_dblBorderColor[0] = 0.0;
	m_dblBorderColor[1] = 0.0;
	m_dblBorderColor[2] = 0.0;
	m_bSelected = false;
	m_bBorderOn = false;
	m_bXYRatio = false;
	m_szFileName = _T("");
}

CCircuitGraph::~CCircuitGraph(void)
{
	Clear();
}

void CCircuitGraph::Serialize(CArchive & ar)
{
	if (ar.IsStoring())
	{
		ar << m_dblStartPosX;
		ar << m_dblStartPosY;
		ar << m_dblEndPosX;
		ar << m_dblEndPosY;
		ar << m_dblWidth;
		ar << m_dblBorderColor[0];
		ar << m_dblBorderColor[1];
		ar << m_dblBorderColor[2];
		ar << m_bSelected;
		ar << m_bBorderOn;
		ar << m_bXYRatio;
		CObj::WriteString(ar,m_szFileName);
	}
	else
	{
		ar >> m_dblStartPosX;
		ar >> m_dblStartPosY;
		ar >> m_dblEndPosX;
		ar >> m_dblEndPosY;
		ar >> m_dblWidth;
		ar >> m_dblBorderColor[0];
		ar >> m_dblBorderColor[1];
		ar >> m_dblBorderColor[2];
		ar >> m_bSelected;
		ar >> m_bBorderOn;
		ar >> m_bXYRatio;
		if (CObj::m_lFileVersion>=70)
		{
			CObj::ReadString(ar,m_szFileName);
		}		
	}

	CCircuitUnit::Serialize(ar);
}

CObj *CCircuitGraph::Clone() const
{
	return new CCircuitGraph(this);
}

void CCircuitGraph::Transform(const CMatrix transf)
{

}

bool CCircuitGraph::GetBox(double & dblLeft, double & dblBottom, double & dblRight, double & dblTop) const
{
	return false;
}

void CCircuitGraph::Clear()
{

}

void CCircuitGraph::CopyDisplayObj(long lSourceLayerId, long lDestLayerId)
{
	CEntityObj::CopyDisplayObj(lSourceLayerId, lDestLayerId);
}

void CCircuitGraph::DeleteDisplayObj(long lLayerId)
{
	CEntityObj::DeleteDisplayObj(lLayerId);
}

CDisplayObj *CCircuitGraph::CreateDisplayObj(long lLayerId)
{
	CCircuitGraphicDisObj *pGraphDis = new CCircuitGraphicDisObj(this);
	pGraphDis->SetLayerId(lLayerId);
	return pGraphDis;
}

void CCircuitGraph::CalcBox()
{
	m_minX = m_dblStartPosX;
	m_minY = m_dblStartPosY;
	m_maxX = m_dblEndPosX;
	m_maxY = m_dblEndPosY;
}

eCircuitUnitEntType CCircuitGraph::GetUnitType() const
{
	return CIRCUIT_GRAPHIC;
}

double CCircuitGraph::GetStartPosX() const
{
	return m_dblStartPosX;
}

double CCircuitGraph::GetStartPosY() const
{
	return m_dblStartPosY;
}

double CCircuitGraph::GetEndPosX() const
{
	return m_dblEndPosX;
}

double CCircuitGraph::GetEndPosY() const
{
	return m_dblEndPosY;
}

double CCircuitGraph::GetBoderWidth() const
{
	return m_dblWidth;
}

double CCircuitGraph::GetColorR() const
{
	return m_dblBorderColor[0];
}

double CCircuitGraph::GetColorG() const
{
	return m_dblBorderColor[1];
}
double CCircuitGraph::GetColorB() const
{
	return m_dblBorderColor[2];
}

bool CCircuitGraph::IsSelect() const
{
	return m_bSelected;
}

bool CCircuitGraph::IsBorderOn() const
{
	return m_bBorderOn;
}

bool CCircuitGraph::IsXYRatio() const
{
	return m_bXYRatio;
}

void CCircuitGraph::SetStartPosX(double dblStartPosX) 
{
	m_dblStartPosX = dblStartPosX;
}

void CCircuitGraph::SetStartPosY(double dblStartPosY) 
{
	m_dblStartPosY = dblStartPosY;
}

void CCircuitGraph::SetEndPosX(double dblEndPosX) 
{
	m_dblEndPosX  = dblEndPosX;
}

void CCircuitGraph::SetEndPosY(double dblEndPosY) 
{
	m_dblEndPosY = dblEndPosY;
}

void CCircuitGraph::SetBoderWidth(double dblBorderWidth) 
{
	m_dblWidth = dblBorderWidth;
}

void CCircuitGraph::SetColorR(double colR) 
{
	m_dblBorderColor[0] = colR;
}

void CCircuitGraph::SetColorG( double colG)
{
	m_dblBorderColor[1] = colG;
}

void CCircuitGraph::SetColorB( double colB)
{
	m_dblBorderColor[2] = colB;
}

void CCircuitGraph::SetSelect( bool bSelected)
{
	m_bSelected = bSelected;
}

void CCircuitGraph::SetBorderOn( bool bBorderOn)
{
	m_bBorderOn = bBorderOn;
}

void CCircuitGraph::SetXYRatio( bool bXYRatio)
{
	m_bXYRatio = bXYRatio;
}
